package com.xingxuecn.limit.web.action;

import com.opensymphony.xwork2.ActionSupport;
import com.xingxuecn.limit.common.model.ResultModel;
import com.xingxuecn.limit.common.utils.ResponseUtils;

import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletResponse;

/**
 * @author Kris at 2018/9/10 15:09
 */
public class ExceptionAction extends ActionSupport {
    private Exception exception;

    @Override
    public String execute() throws Exception {
        exception.printStackTrace();
        //判断是否ajax请求
        /*HttpServletRequest request = ServletActionContext.getRequest();
        boolean isAjaxRequest = false;
        if(!StringUtils.isBlank(request.getHeader("x-requested-with")) && request.getHeader("x-requested-with").equals("XMLHttpRequest")){
            isAjaxRequest = true;
        }*/
        HttpServletResponse response = ServletActionContext.getResponse();
        ResponseUtils.writeJson(new ResultModel<>(500,"系统异常："+exception.getLocalizedMessage()),response);
        return null;
    }

    public Exception getException() {
        return exception;
    }

    public void setException(Exception exception) {
        this.exception = exception;
    }
}
